#include"../include/Car.h"
#include"../include/Tcpserver.h"
#include<exception>
#include<iostream>
#include<string.h>
#include<../include/Json.h>
using namespace CwUtil;
using namespace std;
int main()
{
	string data;
	int car_parmeter=1;
	string car_behave;
	Car car;
	Tcpserver server;
	server.init(10032);
	for(;;)
	{
		if(server.wait_user()==-1)
		{
			continue;
		}
		else
		{
			for(;;)
			{
				data=server.back_message();
				cout<<data<<endl;
				if(data=="")
				{
					continue;
				}
				Json json=Json::parseJson(data);
				if(json.has("status"))
				{
					data=json["status"].asString();
				}
				else
				{
					continue;
				}
				cout<<"!!!"<<endl;
				if(json.has("speed"))
				{
					cout<<"!!!"<<endl;
					car_parmeter=json["speed"].asInt();
				}
				if(json.has("angle"))
				{
					cout<<"!!!"<<endl;
					car_parmeter=json["angle"].asInt();
				}
				cout<<data<<endl;
				cout<<car_parmeter<<endl;
				car.message_deal(data,car_parmeter);
			}
		}
	}
}

/*int main()
{
	string data;
	int speed,angle;
	Car car;
	while(1)
	{
		cout<<"指令："<<endl;
		cin>>data;
		cout<<"输入角度速度"<<endl;
		cin>>speed;
		car.message_deal(data,speed);
	}
}
*/
